package com.gxuwz.easyschool;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button login_button;
    private EditText edit_text_account;
    private EditText edit_text_password;
    private static final String account = "kyg";
    private static final String password = "123456";
    InputMethodManager imm;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (edit_text_account != null) {
            imm.hideSoftInputFromWindow(edit_text_account.getWindowToken(), 0);
        }
        if (edit_text_password != null) {
            imm.hideSoftInputFromWindow(edit_text_password.getWindowToken(), 0);
        }
        return super.onTouchEvent(event);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        login_button = findViewById(R.id.login_button);
        edit_text_account = findViewById(R.id.edit_text_account);
        edit_text_password = findViewById(R.id.edit_text_password);
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        login_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String account = edit_text_account.getText().toString();
                String password = edit_text_password.getText().toString();
                if(account.equals(account) && account.equals(password)){
                    Toast.makeText(MainActivity.this,"账号或密码错误",Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                    startActivity(intent);
                }
            }
        });
    }
}